package com.zyr.controller;

import com.zyr.entity.LoginUser;
import com.zyr.entity.User;
import com.zyr.service.IUserService;
import com.zyr.service.TokenService;
import com.zyr.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * @author: zyr
 * @description:
 **/
@RestController
@RequestMapping("/user")
@RefreshScope
public class UserController {

	@Autowired
	private IUserService userService;
	@Autowired
	private TokenService tokenService;

	@PostMapping("/login")
	public R login(@RequestBody User user){
		LoginUser loginUser = userService.findUser(user);
		if(loginUser != null){
			Map<String,Object> map = tokenService.createToken(loginUser);
			return R.ok().data(map);
		}
		return R.error().message("登录失败！");
	}


}
